﻿using DirectUI.Mobile.UI.Controls;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;
using System;
using DirectUI.Mobile.UI;
namespace UnitTest
{

    public class ComboBoxTestItem
    {
        public ComboBoxTestItem(string text, int value)
        {
            Text = text;
            Value = value;
        }
        public string Text
        {
            get;
            set;
        }
        public int Value
        {
            get;
            set;
        }
    }
    /// <summary>
    ///This is a test class for DirectUIComboBoxTest and is intended
    ///to contain all DirectUIComboBoxTest Unit Tests
    ///</summary>
    [TestClass()]
    public class DirectUIComboBoxTest
    {



        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
      

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for Items
        ///</summary>
        [TestMethod()]
        public void ItemsTest()
        {
     
        }
        private int _selectedItemIndexTestEventNum = 0;
        [TestMethod]
        public void DataBoundTest()
        {
            DirectUIComboBox target = new DirectUIComboBox();
            List<ComboBoxTestItem> items = new List<ComboBoxTestItem>();
            items.Add(new ComboBoxTestItem("hello",1));
            items.Add(new ComboBoxTestItem("hello2",2));
            items.Add(new ComboBoxTestItem("world",3));
            DataBinding bind=new DataBinding();
            bind.DataSource=items;
            target.DataTextField = "Text";
            target.DataValueField = "Value";
            target.SetBinding("Items", bind);
         
            Assert.AreEqual(3, target.Items.Count);
            Assert.AreEqual("hello",((DirectUIComboBoxItem)target.Items[0]).Text);
        }
        /// <summary>
        ///测试
        ///</summary>
        [TestMethod()]
        //public void SelectedItemIndexTest()
        //{
        //    DirectUIComboBox target = new DirectUIComboBox(); // TODO: Initialize to an appropriate value
        //    target.SelectedIndexChanged += new EventHandler(target_SelectedIndexChanged);
        //    try
        //    {
        //        target.Items.Add("wro");
        //    }
        //    catch(Exception ex)
        //    {
        //        Assert.AreEqual("Only Support ComboxBoxItem Type", ex.Message);
        //    }
        //    DirectUIComboBoxItem item = new DirectUIComboBoxItem();
        //    item.Text = "test1";
        //    item.Value = 2;
        //    target.Items.Add(item);
        //    DirectUIComboBoxItem item1 = new DirectUIComboBoxItem();
        //    item1.Text = "test2";
        //    item1.Value = 3;
        //    target.Items.Add(item1);
        //    Assert.AreEqual(((DirectUIComboBoxItem)target.SelectedItem).Value ,2);
        //    target.SelectedItemIndex = 1;
        //    Assert.AreEqual(((DirectUIComboBoxItem)target.SelectedItem).Value, 3);
        //    bool failed=false;
        //    try
        //    {
        //        target.SelectedItemIndex = 5;
        //    }
        //    catch (IndexOutOfRangeException ex)
        //    {
        //        failed = true;
        //    }
        //    Assert.IsTrue(failed);

        //    failed = false;
        //    try
        //    {
        //        target.SelectedItemIndex = -5;
        //    }
        //    catch (IndexOutOfRangeException ex)
        //    {
        //        failed = true;
        //    }
        //    Assert.IsTrue(failed);
        //    Assert.IsTrue(_selectedItemIndexTestEventNum == 1);
        //}

        void target_SelectedIndexChanged(object sender, EventArgs e)
        {
            _selectedItemIndexTestEventNum++;
        }

    }
}
